﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>同步表维护</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style>
        .easyui-linkbutton{margin-left:20px;}
        table tr td{padding:0px 5px}
       #fm .l-btn-text{margin-top:3px}
       .toappid{display:none;}
       .containerOrProduct,.employee{display:none}
    </style>
</head>
<body>
 <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td class="tablename">表名:</td>
                    <td class="containerOrProduct">件号/批次:</td>
                    <td class="toappid toappidemp">目标系统:</td>
                    <td class="toappid">创建时间:</td>
                    <td class="employee">分厂:</td>
                    <td class="employee">工区:</td>
                    <td class="employee">班组:</td>
                    <td class="employee">姓名:</td>
	    		</tr>
	    		<tr>
	    			<td class="tablename"><input  name="tablename" class="easyui-combobox" style="width: 250px; height: 22px" id="tablename"/></td>
                    <td class="containerOrProduct"><input  name="containerOrProduct" class="easyui-textbox" style="width: 250px; height: 22px" id="Text1"/></td>
                    <td class="toappid toappidemp"><input  name="toappid" class="easyui-combobox" style="width: 120px; height: 22px" id="toappid"/></td>
                    <td class="toappid"><input  name="startDate" class="easyui-datetimebox" style="width: 170px; height: 22px" id="startDate"/> -
                        <input  name="endDate" class="easyui-datetimebox" style="width: 170px; height: 22px" id="endDate"/>
                    </td>
                    <td class="employee"><select id='ddlFactory' data-options='editable:false' class='easyui-combobox'style="width: 160px;height: 22px"></select></td>
                    <td class="employee"><select id='ddlWorkcenter' data-options='editable:false' class='easyui-combobox' style="width: 120px;height: 22px"></select></td>
                    <td class="employee"><select id='ddlTeam' data-options='editable:false' class='easyui-combobox' style="width: 120px;height: 22px"></select></td>
                    <td class="employee"><input id="txtFullname" class="easyui-textbox" style="width: 100px;height: 22px" /></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
	    		</tr>
	    	</table>
	    </form>
        </div> 
    </div>
    <div class="panelSection">
    <div class="easyui-tabs" id="tt">
          <div title="表结构同步记录维护"> 
            <table id="syncTableInfo" style="height:440px" data-options="rownumbers:true"></table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
                    </div>
             <div style="margin-top:7px">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.appendRow('syncTableInfo',{ID:'',TABLENAME:'',UNIQUECOLNAME:'',SYNC_INTERVAL:''})">新增</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.saveSyncTableInfo()">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleteSyncTableInfo()">删除</a>
             </div>
             </div>
          <!--<div title="表结构同步任务">
                <table id="syncTableTask" style="height:440px" data-options="rownumbers:true"></table>
                <div id="ppp" style="float: right" class="easyui-pagination" data-options="   
                     layout:['first','prev','next','last','manual','info'],              
                        total: 0,
                        showPageList: false,
                        showPageInfo: false,
                        showRefresh: false,
                        afterPageText:'共&nbsp{pages}&nbsp页',
                         buttons:[{
                                iconCls:'',
                                text:'Go',
                                id:'ppageGo'
                        }]
                    ">
                        </div>
                 <div style="margin-top:7px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.appendRow('syncTableTask',{ID:'',TABLENAME:'',OPERATETYPE:'',ISHANDLE:''})">新增</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.saveSyncTableTask()">保存</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleteSyncTableTask()">删除</a>
                 </div>
             </div>-->
          <div title="表数据推送产线记录">
                <table id="syncTablePush" style="height:440px" data-options="rownumbers:true"></table>
                <div id="pppp" style="float: right" class="easyui-pagination" data-options="   
                     layout:['first','prev','next','last','manual','info'],              
                        total: 0,
                        showPageList: false,
                        showPageInfo: false,
                        showRefresh: false,
                        afterPageText:'共&nbsp{pages}&nbsp页',
                         buttons:[{
                                iconCls:'',
                                text:'Go',
                                id:'pppageGo'
                        }]
                    ">
                        </div>
                         <div style="margin-top:7px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.sendAgin(null,'1')">批量重推</a>
                 </div>
             </div>
             <div title="推送产线记录">
                <table id="sendRecord" style="height:400px" data-options="rownumbers:true"></table>
                <div id="sendPage" style="float: right" class="easyui-pagination" data-options="   
                     layout:['first','prev','next','last','manual','info'],              
                        total: 0,
                        showPageList: false,
                        showPageInfo: false,
                        showRefresh: false,
                        afterPageText:'共&nbsp{pages}&nbsp页',
                         buttons:[{
                                iconCls:'',
                                text:'Go',
                                id:'sendpageGo'
                        }]
                    ">
                 </div>
                 <div class="easyui-tabs " id="ttt" data-options="" style="height:400px;width:100%">
                    <div title="工序工步信息">
                        <table id="Table0" style="height:400px"  data-options="rownumbers:true,fit:true"></table>
                    </div>
                    <div title="工装工具信息">
                       <table id="Table1" style="height:400px" data-options="rownumbers:true,fit:true"></table>
                    </div>
                    <div title="检测项信息">
                       <table id="Table2" style="height:400px" data-options="rownumbers:true,fit:true"></table>
                    </div>
                    <div title="报工信息">
                       <table id="Table3" style="height:400px" data-options="rownumbers:true,fit:true"></table>
                    </div>
                    <div title="BOM">
                       <table id="Table4" style="height:380px" data-options="rownumbers:true,fit:true"></table>
                    </div>
                </div>
                <div class="sendAgin"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="send.sendAgin(null)">批量重推</a></div> 
             </div>
             <div title="人员信息">
                <table id="employee" style="height:440px" data-options="rownumbers:true"></table>
                <div id="employeePage" style="float: right" class="easyui-pagination" data-options="   
                     layout:['first','prev','next','last','manual','info'],              
                        total: 0,
                        showPageList: false,
                        showPageInfo: false,
                        showRefresh: false,
                        afterPageText:'共&nbsp{pages}&nbsp页',
                         buttons:[{
                                iconCls:'',
                                text:'Go',
                                id:'emppageGo'
                        }]
                    ">
                        </div>
                         <div style="margin-top:7px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="employee.sendAgin()">批量重推</a>
                 </div>
             </div>
    </div>
    </div>
     
    <div id="dlg" title="推送数据及记录"  style="width:400px;height:200px;padding:10px;display:none">
        <table id="syncTablePushData" style="height:100px" data-options="rownumbers:true"></table>
        <table id="syncTableSendData" style="height:250px" data-options="rownumbers:true"></table>
         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.appendRow('syncTableSendData',{ID:'',TOAPPID:'',ISMESHANDLE:'0'})">新增</a>
         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.saveSyncTableSendData()">保存</a>
         <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleSyncTableSendData()">删除</a>
    </div>
     <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/dayjs.min.js" type="text/javascript"></script>
<script type="text/javascript">
    //创建人：longb
    //日期：2024-01-10
    //描述：同步表维护
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        pagetotal2: 0,
        pageSize2: 20,
        pageNumber2: 1,
        pagetotal3: 0,
        pageSize3: 20,
        pageNumber3: 1,
        editIndex:undefined,
        team:null,
        workcenter:null,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/SyncTableInfoHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
            page.initData();
        },
        endEditing:function(id){
             if (page.editIndex == undefined){return true}   
             if ($('#'+id).datagrid('validateRow', page.editIndex)){
				var ed = $('#'+id).datagrid('getEditor', {index:page.editIndex});
				$('#'+id).datagrid('endEdit', page.editIndex);
				page.editIndex = undefined;
				return true;
			} else {
				return false;
			}
        },
        initData:function(){
         page.post({action:'InitPageData'}, function (res) {
                    $('#tablename').combobox({
                        data:res.DBTable,
                        valueField:'TABLENAME',
                        textField:'TABLENAME'
                    });
                   $('#toappid').combobox({
                        data:res.ReturnData,
                        valueField:'TOAPPID',
                        textField:'TOAPPID'
                    });
                   
            });
        },
        //页面事件绑定
        bind: function () {
            $('#syncTableInfo').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                 {field:'ck',checkbox:true},
                 { field: 'TABLENAME', title: '表名', width: 100,align:'center',editor:{type:'textbox',options:{required:true}} },
                 { field: 'UNIQUECOLNAME', title: '唯一列名', width: 150,editor:{type:'textbox',options:{required:true}} },
		         { field: 'SYNC_INTERVAL', title: '间隔（分钟）', width: 150,editor:'numberbox' },
                 { field: 'NEXTSYNCTIME', title: '下次同步时间', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                 { field: 'LASTSYNCTIME', title: '上次同步时间', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                 { field: 'CREATETIME', title: '创建时间', width: 150,formatter:function(value,row,index){return dayjs(value).format('YYYY-MM-DD HH:mm:ss');} },
                 { field: 'LASTCHANGETIME', title: '最后修改时间', width: 150,formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD HH:mm:ss');} }},
                 { field: 'OP', title: '操作', width: 150,align:'center',formatter:function(value,row,index){
                       var rowdata=JSON.stringify({TABLENAME:row.TABLENAME,ID:row.ID,TYPE:''});
                       return "<button onclick=page.openDialog('"+rowdata+"') style='cursor:pointer;width: 40px; height: 22px'>查看</button>"; 
                  }}
                ]],
                onClickRow:function(index,row){
                    page.onClickRow(index,'syncTableInfo');
                },
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.getSyncTableInfo();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.getSyncTableInfo();
            });

            $('#syncTableTask').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                 {field:'ck',checkbox:true},
                 { field: 'TABLENAME', title: '表名', width: 100,align:'center',editor:'textbox' },
                 { field: 'OPERATETYPE', title: '任务类型', width: 150,editor:{type:'combobox',options:{valueField:'id',textField:'text',panelHeight:'auto',required:true,data:[{id:4,text:'创建表结构'},{id:5,text:'删除表结构'},{id:6,text:'全量数据同步'}]}},
                    formatter:function(value,row){if(value==4){return '创建表结构'}else if(value==5){return '删除表结构'}else if(value==6){return '全量数据同步'}else{return ''} }},
		         { field: 'ISHANDLE', title: '状态', width: 150,formatter:function(value,row){if(value==0){return '未处理'}else{return '已处理'} }},
                 { field: 'CREATETIME', title: '创建时间', width: 150,formatter:function(value,row,index){return dayjs(value).format('YYYY-MM-DD HH:mm:ss');} },
                 { field: 'LASTCHANGETIME', title: '最后修改时间', width: 150,formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD HH:mm:ss');} }}
                ]],
                onClickRow:function(index,row){
                    page.onClickRow(index,'syncTableTask');
                },
                onLoadSuccess: function (data) {
                    $('#ppp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal2,
                        pageSize: page.pageSize2,
                        pageNumber: page.pageNumber2
                    });
                    customizedEasyuiPagination('ppp'); //定制化分页
                },
            });
            //分页事件
            $('#ppp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize2 = pageSize; page.pageNumber2 = pageNumber;
                    page.getSyncTableTask();
                }
            });
            //绑定分页go按钮
            $('#ppageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber2 = pageNumber;
                page.getSyncTableTask();
            });

            $('#syncTablePush').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                 {field:'ck',checkbox:true},
                 { field: 'TABLENAME', title: '表名', width: 100,align:'center',editor:'textbox' },
                 { field: 'UNIQUECOLNAME', title: '唯一列名', width: 150 },
                 { field: 'UNIQUECOLVALUE', title: '唯一列名值', width: 150 },
                 { field: 'OPERATETYPE', title: '数据类型', width: 150,align:'center',
                    formatter:function(value,row){if(value==1){return '新增'}else if(value==2){return '修改'}else if(value==3){return '删除'}else{return ''} }},
                 { field: 'CREATETIME', title: '创建时间', width: 150,formatter:function(value,row,index){return dayjs(value).format('YYYY-MM-DD HH:mm:ss');} },
                 { field: 'OP', title: '操作', width: 150,align:'center',formatter:function(value,row,index){
                        row.OLDVALUE=null;
                        row.NEWVALUE=null;
                       return "<button   class='' onclick=page.openDialog('"+JSON.stringify(row)+"') style='cursor:pointer;width: 40px; height: 22px'>查看</button>"; 
                  }}
                ]],
                onLoadSuccess: function (data) {
                    $('#pppp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal3,
                        pageSize: page.pageSize3,
                        pageNumber: page.pageNumber3
                    });
                    customizedEasyuiPagination('pppp'); //定制化分页
                },
            });
            //分页事件
            $('#pppp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pppp'); //定制化分页
                    page.pageSize3 = pageSize; page.pageNumber3 = pageNumber;
                    page.getSyncTablePush();
                }
            });
            //绑定分页go按钮
            $('#pppageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber3 = pageNumber;
                page.getSyncTablePush();
            });
            $('#tt').tabs({
            onSelect:function(title,index){
             if(index==1){$('.toappid').show();$('.containerOrProduct,.employee').hide();$('.tablename').show();
             }else if(index==2){
                $('.toappid').show();$('.containerOrProduct').show();$('.tablename,.employee').hide();
             }else if(index==3){
                $('.tablename,.containerOrProduct,.toappid').hide();$('.employee,.toappidemp').show();
             }
             else{$('.toappid').hide();$('.containerOrProduct,.employee').hide();$('.tablename').show()}
            }
            });
           
        },
        //查询
        searchData: function () {
        var tab = $('#tt').tabs('getSelected');
        var index = $('#tt').tabs('getTabIndex',tab);
         clearMessage();
         if(index==0){
             page.pageNumber = 1;
             page.getSyncTableInfo();
            }else if(index==1){
                page.pageNumber3 = 1;
                page.getSyncTablePush();
               
            }else if(index==2){
                send.getSyncTablePushRecord();
            }else if(index==3){
                employee.getEmployeeData();
            }
            else{
                page.pageNumber2 = 1;
                page.getSyncTableTask();
            }
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            clearMessage();
        },
        getSyncTableInfo:function(){
          var tab = $('#tt').tabs('getSelected');
          var index = $('#tt').tabs('getTabIndex',tab);
            var param = {
                action: "getSyncTableInfoOrTask",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                selectTable:'sync_TableInfo',
                tablename: $('#tablename').combobox('getValue'),
                data:null
            };
            page.post(param, function (res) {
                if (res.Result) {
                    page.pagetotal = res.RowCount;
                    $('#syncTableInfo').datagrid('loadData', res.DBTable);
                }
            });
        },
        
        deleteSyncTableInfo:function(){
            var rows=$('#syncTableInfo').datagrid('getChecked');
            if(rows.length==0){displayMessage('请选择至少一条信息再进行操作',false);return;}
            page.post({action:'deleteSyncTableInfo',data:JSON.stringify(rows)}, function (res) {
                 if(res.Result){
                    page.getSyncTableInfo();
                 }
                 displayMessage(res.Message, res.Result);
            })
        },
        
        ///保存
        saveSyncTableInfo:function(){
            $('#syncTableInfo').datagrid('endEdit',page.editIndex);
            var rows= $('#syncTableInfo').datagrid('getChanges');
            var param = {
                action: "saveSyncTableInfo",
                data:JSON.stringify(rows)
                }
           page.post(param, function (res) {
                if (res.Result) {
                    page.getSyncTableInfo();
                }
                displayMessage(res.Message, res.Result);
           });
        },

        getSyncTableTask:function(){
            var param = {
                action: "getSyncTableInfoOrTask",
                pageSize: page.pageSize2,
                pageNumber: page.pageNumber2,
                selectTable:'sync_TableTask',
                tablename: $('#tablename').combobox('getValue'),
                data:null
            };
            page.post(param, function (res) {
                if (res.Result) {
                    page.pagetotal2 = res.RowCount;
                    $('#syncTableTask').datagrid('loadData', res.DBTable);
                }
            });
        },
        
        deleteSyncTableTask:function(){
            var rows=$('#syncTableTask').datagrid('getChecked');
            if(rows.length==0){displayMessage('请选择至少一条信息再进行操作',false);return;}
            page.post({action:'deleteSyncTableTask',data:JSON.stringify(rows)}, function (res) {
                 if(res.Result){
                    page.getSyncTableTask();
                 }
                 displayMessage(res.Message, res.Result);
            })
        },
        
        ///保存
        saveSyncTableTask:function(){
            $('#syncTableTask').datagrid('endEdit',page.editIndex);
            var rows= $('#syncTableTask').datagrid('getChanges');
            var param = {
                action: "saveSyncTableTask",
                data:JSON.stringify(rows)
                }
           page.post(param, function (res) {
                if (res.Result) {
                    page.getSyncTableTask();
                }
                displayMessage(res.Message, res.Result);
           });
        },
        getSyncTablePush:function(){
         $('#syncTablePush').datagrid('loadData', []);
             var frdata = $('#searchForm').serializeArray();
             var data = {};
                $.each(frdata, function () {
                    data[this.name] = this.value
                });
             var param = {
               action: "getSyncTableInfoOrTask",
                pageSize: page.pageSize3,
                pageNumber: page.pageNumber3,
                selectTable:'sync_TableChangeRecord',
                tablename: $('#tablename').combobox('getValue'),
                data:JSON.stringify(data)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    page.pagetotal3 = res.RowCount;
                    $('#syncTablePush').datagrid('loadData', res.DBTable);
                }
            });
        },
        openDialog:function(data){
            $('#dlg').dialog({
                    title: '推送信息及记录',
                    width: 700,
                    height: 550,
                    closed: false,
                    modal: true
                });
           page.getsyncTableSendData(data);
        },
        getsyncTableSendData:function(data){
             var param = {
               action: "getSyncTableChangeRecord",
               data: data
            };
            page.post(param, function (res) {
                if (res.Result) {
                  var columns=[];
                  $.each(res.DBTable,function(index,item){
                        columns.push({field: item.COLUMN_NAME, title: item.COLUMN_NAME, width: 150});
                  });
                   $('#syncTablePushData').datagrid({
                    columns:[columns],
                    data:res.ReturnData,
                    onLoadSuccess: function(data){
                            setTimeout(function(){
                                $('#syncTablePushData').datagrid('resize', {
                                    height: 200  // 设置新的高度为300
                                });
                            }, 0);
                        }
                   });
                    $('#syncTableSendData').datagrid({
                    columns:[[{field:'ck',checkbox:true},{field:'TOAPPID', title: '推送目标系统', width: 150,editor:{type:'textbox',options:{required:true}}},
                        {field: 'ISMESHANDLE', title: '状态', width: 150,formatter:function(value,row,index){
                            return value==0?'未推送':'已推送';
                        }},
                         { field: 'OP', title: '操作', width: 150,align:'center',formatter:function(value,row,index){
                         if(row.ISMESHANDLE==0){return ''}else{
                         return "<button   class='' onclick=page.sendAgin('"+JSON.stringify(row)+"','0') style='cursor:pointer;width: 40px; height: 22px'>重推</button>"; 
                         }
                        }}
                    ]],
                   onClickRow:function(index,row){
                        page.onClickRow(index,'syncTableSendData');
                    },
                    data:res.DBDataSet.sendtoappid
                   });
                }
            });
        },
        sendAgin:function(data,type){
            if(type=='1'){
                data=JSON.stringify( $('#syncTablePush').datagrid('getChecked'));
            }
            var toappid=$('#toappid').combobox('getValue');
            var param = {
               action: "sendAginSyncTableChangeRecord",
               data: data,
               type:type,
               toappid:toappid
            };
            page.post(param, function (res) {
                 if (res.Result&&type=='0') {
                   var data=$('#syncTablePush').datagrid('getSelected');
                   page.getsyncTableSendData(JSON.stringify(data));
                }
                displayMessage(res.Message, res.Result);
            });
        },
        saveSyncTableSendData:function(){
            $('#syncTableSendData').datagrid('endEdit',page.editIndex);
            var rows= $('#syncTableSendData').datagrid('getChanges');
            if(rows.length==0){return;}
            var row=$('#syncTablePush').datagrid('getSelected');
            var tab = $('#tt').tabs('getSelected');
            var index = $('#tt').tabs('getTabIndex',tab);
            if(index==0){
                row=$('#syncTableInfo').datagrid('getSelected');
            }
            var param = {
                action: "saveSynSendData",
                data:JSON.stringify(rows),
                parentid:row.ID
                }
           page.post(param, function (res) {
                if (res.Result) {
                   page.getsyncTableSendData(JSON.stringify(row));
                }
                displayMessage(res.Message, res.Result);
           });
        },
        deleSyncTableSendData:function(){
            var rows=$('#syncTableSendData').datagrid('getChecked');
            if(rows.length==0){displayMessage('请选择至少一条信息再进行操作',false);return;}
            page.post({action:'deleteSynSendData',data:JSON.stringify(rows)}, function (res) {
                 if(res.Result){
                 var row=$('#syncTablePush').datagrid('getSelected');
                     page.getsyncTableSendData(JSON.stringify(row));
                 }
                 displayMessage(res.Message, res.Result);
            })
        },
        appendRow:function(id,columns){
            $('#syncTableInfo').datagrid('endEdit',page.editIndex);
            if (page.endEditing(id)){
				$('#'+id).datagrid('appendRow',columns);
				page.editIndex = $('#'+id).datagrid('getRows').length-1;
				$('#'+id).datagrid('selectRow', page.editIndex).datagrid('beginEdit', page.editIndex);
			}
        },
        onClickRow:function(index,id){
            $('#syncTableInfo').datagrid('endEdit',page.editIndex);
            page.editIndex=undefined;
            if (page.editIndex != index){
				if (page.endEditing(id)){
					$('#'+id).datagrid('selectRow', index).datagrid('beginEdit', index);
					page.editIndex = index;
				} else {
					$('#'+id).datagrid('selectRow', page.editIndex);
				}
			}
        },
        //post数据
        post: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        },
        postasync: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    //$.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    var send={
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
         //初始化页面
        init: function () {
            send.bind();
        },
        bind:function(){
            {
            $('#sendRecord').datagrid({
//                checkOnSelect: false,
//                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
//                 {field:'ck',checkbox:true},
                 { field: 'FACTORYNAME', title: '分厂', width: 130,align:'center' },
                 { field: 'MFGORDERNAME', title: '生产订单', width: 130,align:'center' },
                 { field: 'PRODUCTINFO', title: '件号/版本', width: 150, },
                 { field: 'WORKFLOWINFO', title: '工艺路线/版本', width: 150, },
		         { field: 'CONTAINERNAME', title: '批次号', width: 150, },
                 { field: 'TOAPPID', title: '产线', width: 150, },
                 { field: 'SENDTIME', title: '批次推送时间', width: 150,formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                 { field: 'BUSINESSID', title: '批次推送回传ID', width: 150,formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                 { field: 'OP', title: '操作', width: 150,align:'center',formatter:function(value,row,index){
                       var rowdata=JSON.stringify(row);
                       return "<button onclick=send.sendAgin('"+rowdata+"') style='cursor:pointer;width: 40px; height: 22px'>重推</button>"; 
                  }}
                ]],
                onClickRow:function(index,row){
                    send.getSyncTablePushRecordDetail(row);
                },
                onLoadSuccess: function (data) {
                    $('#sendPage').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: send.pagetotal,
                        pageSize: send.pageSize,
                        pageNumber: send.pageNumber
                    });
                    customizedEasyuiPagination('sendPage'); //定制化分页
                },
            });
            //分页事件
            $('#sendPage').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('sendPage'); //定制化分页
                    send.pageSize = pageSize; page.pageNumber = pageNumber;
                    send.getSyncTablePushRecord();
                }
            });
            //绑定分页go按钮
            $('#sendpageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                send.pageNumber = pageNumber;
                send.getSyncTablePushRecord();
            });
        }
        
            {
                $('#Table0').datagrid({
                    checkOnSelect: false,
                    selectOnCheck: false,
                    singleSelect: true,
                    rownumbers: true,
                    columns: [[
                     {field:'ck',checkbox:true},
                     { field: 'SPECNO', title: '工序号', width: 100,align:'center'},
                     { field: 'WORKFLOWSTEPNAME', title: '工序名称', width: 150 },
                     { field: 'STEPNO', title: '工步号', width: 150 },
		             { field: 'STEPINFONAME', title: '工步名称', width: 150 },
                     { field: 'SENDTIME', title: '工序推送时间', width: 150,formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                     { field: 'BUSINESSID', title: '工序推送回传ID', width: 150,formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                    ]]
                });

                $('#Table1').datagrid({
                    checkOnSelect: false,
                    selectOnCheck: false,
                    singleSelect: true,
                    rownumbers: true,
                    columns: [[
                     {field:'ck',checkbox:true},
                     { field: 'WORKFLOWSTEPNAME', title: '工序', width: 100,align:'center'},
                     { field: 'WORKFLOWSTEPNAME', title: '工步', width: 100,align:'center'},
                     { field: 'DRAWINGNO', title: '工具编号', width: 150 },
                     { field: 'NAME', title: '工具名称', width: 150 },
                     { field: 'QTY', title: '使用数量', width: 150 },
                     { field: 'SENDTIME', title: '推送时间', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                     { field: 'BUSINESSID', title: '推送回传ID', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                    ]],
                });

                $('#Table2').datagrid({
                    checkOnSelect: false,
                    selectOnCheck: false,
                    singleSelect: true,
                    rownumbers: true,
                    columns: [[
                     {field:'ck',checkbox:true},
                     { field: 'WORKFLOWSTEPNAME', title: '工序', width: 100,align:'center'},
                     { field: 'WORKFLOWSTEPNAME', title: '工步', width: 100,align:'center'},
                     { field: 'CHECKPOINTNOTEDIS', title: '检测项内容', width: 150 },
                     { field: 'DRAWINGREQUIREDIS', title: '图纸规定', width: 150 },
		             { field: 'CHECKNO', title: '检验序号', width: 150 },
                     { field: 'WORKCHECKPOINTRESULTNOTEDIS', title: '工人实测值', width: 150 },
                     { field: 'CHECKPOINTRESULTNOTEDIS', title: '检验实测值', width: 150 },
                     { field: 'FULLNAME', title: '检验员', width: 150 },
                     { field: 'CHECKDATE', title: '检验时间', width: 150 },
                     { field: 'SENDTIME', title: '推送时间', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                     { field: 'BUSINESSID', title: '推送回传ID', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                    ]],
                });

                $('#Table3').datagrid({
                    checkOnSelect: false,
                    selectOnCheck: false,
                    singleSelect: true,
                    rownumbers: true,
                    columns: [[
                     {field:'ck',checkbox:true},
                     { field: 'TABLENAME', title: '工序', width: 100,align:'center'},
                     { field: 'UNIQUECOLNAME', title: '报工人', width: 150 },
		             { field: 'SYNC_INTERVAL', title: '报工时间', width: 150 },
                    ]],
                });

                $('#Table4').datagrid({
                    checkOnSelect: false,
                    selectOnCheck: false,
                    singleSelect: true,
                    rownumbers: true,
                    columns: [[
                     {field:'ck',checkbox:true},
                     { field: 'SPECNAME', title: '工序', width: 100,align:'center'},
                     { field: 'STEPINFODESC', title: '工步', width: 100,align:'center'},
                     { field: 'PRODUCTINFO', title: '件号信息', width: 150 },
		             { field: 'QTYREQUIRED', title: '初装数', width: 150 },
                     { field: 'QTY2REQUIRED', title: '检装数', width: 150 },
                     { field: 'BIGSMALLPART', title: '零件类别', width: 150 },
                     { field: 'NOTES', title: '备注', width: 150 },
                     //{ field: 'SENDTIME', title: '推送时间', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                     //{ field: 'BUSINESSID', title: '推送回传ID', width: 150,editor:'datebox',formatter:function(value,row,index){if(value==null||value==""){return '' }else{return dayjs(value).format('YYYY-MM-DD');}} },
                    ]],
                });

            }

            $('#ttt').tabs({
            onSelect:function(title,index){
                 if(index==3){$('.sendAgin').hide();}else{$('.sendAgin').show();}
            }});
        },
        getSyncTablePushRecord:function(){
            send.pageNumber=1;
            $('#sendRecord').datagrid('loadData', []);
             var frdata = $('#searchForm').serializeArray();
             var data = {};
                $.each(frdata, function () {
                    data[this.name] = this.value
                });
             var param = {
                action: "getSyncTablePushRecord",
                pageSize: send.pageSize,
                pageNumber: send.pageNumber,
                data:JSON.stringify(data)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    send.pagetotal = res.RowCount;
                    $('#sendRecord').datagrid('loadData', res.DBTable);
                }
            });
        },
        getSyncTablePushRecordDetail:function(row){
         var param = {
                action: "getSyncTablePushRecordDetail",
                data:JSON.stringify(row)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    $('#Table0').datagrid('loadData', res.DBDataSet.workflowDT);
                    $('#Table1').datagrid('loadData', res.DBDataSet.stepinfoDT);
                    $('#Table2').datagrid('loadData', res.DBDataSet.checkpointDT);
                    $('#Table3').datagrid('loadData', res.DBDataSet.workreportDT);
                    $('#Table4').datagrid('loadData', res.DBDataSet.bomDT);
                }
            });
        
        },
        sendAgin:function(row){
           var tab = $('#ttt').tabs('getSelected');
           var index = $('#ttt').tabs('getTabIndex',tab);
           var data=$('#Table'+index).datagrid('getChecked');
           if(data.length==0&&row==null){displayMessage('请选择至少一条信息再进行操作',false);return;}
           var param = {
                action: "sendAginRecord",
                index:row==null?index:null,
                mdata:row==null?JSON.stringify($('#sendRecord').datagrid('getSelected')):row,
                data:JSON.stringify(data)
            };
            page.post(param, function (res) {
                 displayMessage(res.Message, res.Result);
            });
        }
    };
    var employee={
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        mainUrl: getRootPath() + "/Ashx/ApsHandler/EmployeeMaintPage.ashx", //本页面后台路径
        init:function(){
            employee.bind();
            employee.getFactory();
        },
        bind:function(){
            $('#employee').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                { field: 'ck', title: '选择', checkbox: true },
                { field: 'employeeid', title: '员工id', hidden: true },
                { field: 'employeename', title: '员工号', width: 100 },
                { field: 'fullname', title: '姓名', width: 80 },
                { field: 'cardnum', title: '卡号', width: 90 },
                { field: 'factoryname', title: '分厂', width: 130 },
                { field: 'workcentername', title: '工区', width: 100 },
                { field: 'teamname', title: '班组', width: 80 },
                { field: 'workshiftname', title: '班次', width: 80 },
                { field: 'workshiftid', title: '班次id', hidden: true },
                { field: 'rolenames', title: '角色', width: 150 },
                ]],
                onLoadSuccess: function (data) {
                    $('#employeePage').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: employee.pagetotal,
                        pageSize: employee.pageSize,
                        pageNumber: employee.pageNumber
                    });
                    customizedEasyuiPagination('employeePage'); //定制化分页
                },
            });
            //分页事件
            $('#employeePage').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('employeePage'); //定制化分页
                    employee.pageSize = pageSize; employee.pageNumber = pageNumber;
                    employee.getEmployeeData();
                }
            });
            //绑定分页go按钮
            $('#emppageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                employee.pageNumber = pageNumber;
                employee.getEmployeeData();
            });
        },
        getEmployeeData:function(){
            var formData = {
              action: "GetEmployee",
              pageSize: employee.pageSize,
              pageNumber: employee.pageNumber,
              rolename: '',
              factoryid: $('#ddlFactory').combobox('getValue'),
              workcenterid: $('#ddlWorkcenter').combobox('getValue'),
              teamid: $('#ddlTeam').combobox('getValue'),
              fullname: $('#txtFullname').textbox('getValue'),
              employeename: ''
            };
         employee.postasync(formData, function (res) {
                if (res.Result) {
                    employee.pagetotal = res.RowCount;
                    $('#employee').datagrid('loadData', res.DBTable);
                }
            });
        },
        // 获取分厂列表
        getFactory: function () {
            var formData={
                action: "GetFactory"
            }
            employee.postasync(formData, function (res) {
                res.DBTable.unshift({ factoryid: '', factoryname: '' });
                  $("#ddlFactory").combobox({
                    valueField: 'factoryid',
                    textField: 'factoryname',
                    panelHeight: 200,
                    data: res.DBTable, //下拉数据
                    onSelect: function (record) {
                      if (record.factoryid) {
                        employee.bindWorkcenter(record.factoryid);// 加载工区
                        // 清空班组
                        $('#ddlTeam').combobox('clear');
                        $('#ddlTeam').combobox('loadData', []);
                      }
                    }
                  });
        
            });
        },
        // 绑定工区
        bindWorkcenter: function (factoryid) {
            var formData={ action: "GetWorkcenter", factoryid: factoryid }
             employee.postasync(formData, function (res) {
                if (res.Result) {
                  //绑定工区
                  res.DBTable.unshift({ workcenterid: '', workcentername: '' });
                  $("#ddlWorkcenter").combobox({
                    valueField: 'workcenterid',
                    textField: 'workcentername',
                    panelHeight: 200,
                    data: res.DBTable, //下拉数据
                    onSelect: function (record) {
                      if (record.workcenterid) {
                        employee.bindTeam(record.workcenterid); //加载班组
                      }
                    }
                  });
                  $("#ddlWorkcenter").combobox('select', '');
                } else {
                  displayMessage(res.Message, res.Result);
                }
             });
        },
        // 绑定班组
        bindTeam: function (workcenterid) {
             var formData={ action: "GetTeam", workcenterid: workcenterid }
             employee.postasync(formData, function (res) {
                if (res.Result) {
                  //绑定班组
                  res.DBTable.unshift({ teamid: '', teamname: '' });
                  $("#ddlTeam").combobox({
                    valueField: 'teamid',
                    textField: 'teamname',
                    panelHeight: 200,
                    data: res.DBTable, //下拉数据
                  });
                  $("#ddlTeam").combobox('select', '');
                } else {
                  displayMessage(res.Message, res.Result);
                }
             });
        },
        sendAgin:function(){
            var toappid=$('#toappid').combobox('getValue');
            var data=$('#employee').datagrid('getChecked');
            if(toappid==null||toappid==''){
                displayMessage('请选择目标系统再进行操作',false);return;
            }
            if(data.length==0){
                displayMessage('请勾选人员信息再进行操作',false);return;
            }
            var param = {
               action: "sendAginEmployeeData",
               data:JSON.stringify(data),
               toappid:toappid
            };
            page.post(param, function (res) {
                displayMessage(res.Message, res.Result);
            });
        },
        postasync: function (param, callback) {
            $.ajax({
                type: "Post",
                url: employee.mainUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    //$.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    };
    $(function () {
        page.init();
        send.init();
        employee.init();
    });
</script>
